1 package jrre.instructionset.objects;
2
3 import jrre.*;
4 import jrre.types.*;
5 import jrre.classloader.classfile.pool_entries.*;
6
7 public class GetField extends jrre.instructionset.Instruction {
8
9 private int operandOne;
10 private int operandTwo;
11
12 public GetField(int operandOne, int operandTwo){
13
14 this.operandOne = operandOne;
15 this.operandTwo = operandTwo;
16
17 name = "getfield "+operandOne+" "+operandTwo;
18 description = "pushes a field.";
19 length = 2;
20 }
21
22 /***
23 * Executes the <strong><code>getfield</code></strong> instruction.
24 *
25 */
26 public void execute(){
27
28 int fieldIndex = (operandOne << 8 | operandTwo);
29
30 Type referenceToGetFrom = Stack.popOperand();
31
32 //System.out.println("GF: "+referenceToGetFrom+" "+fieldIndex);
33
34 ObjectInstance objectToGetFrom = ((ReferenceType)referenceToGetFrom).getValue();
35
36 Type fieldValue = objectToGetFrom.getInstanceValue(fieldIndex);
37
38 //System.out.println(fieldValue);
39 if(fieldValue == null)
40 fieldValue = new PrimitiveType(0);
41 //fieldValue = new NullReference();
42
43 //System.out.println(referenceToGetFrom+" "+fieldValue);
44
45 Stack.pushOperand(fieldValue);
46
47 }
48
49 public String toString(){
50 StringBuffer toReturn = new StringBuffer();
51 toReturn.append("getfield ");
52 toReturn.append(Integer.toHexString(operandOne));
53 toReturn.append(" ");
54 toReturn.append(Integer.toHexString(operandTwo));
55 return toReturn.toString();
56 }
57 }
This page was automatically generated by Maven